package com.example.reclameaquidoseuonibus.adapter;

import java.util.List;

import com.example.reclameaquidoseuonibus.R;
import com.example.reclameaquidoseuonibus.R.drawable;
import com.example.reclameaquidoseuonibus.R.id;
import com.example.reclameaquidoseuonibus.R.layout;
import com.example.reclameaquidoseuonibus.entidades.Reclamacao;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ReclamacaoAdapter extends BaseAdapter{

	private List<Reclamacao> recl;
	private Context context;
	
	public ReclamacaoAdapter (List<Reclamacao> recl, Context context){
		this.recl = recl;
		this.context = context;
	}
	
	@Override
	public int getCount() {
		return this.recl.size();
	}

	@Override
	public Object getItem(int position) {
		return this.recl.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		LayoutInflater inflater = (LayoutInflater)
				this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View lineView = inflater.inflate(R.layout.feed_item, null);
		
		TextView textEmp = (TextView) lineView.findViewById(R.id.empresa);
		TextView textRecl = (TextView) lineView.findViewById(R.id.reclamacao);
		ImageView imgSituation = (ImageView) lineView.findViewById(R.id.situacao);
		
		Reclamacao recl = this.recl.get(position);
		
		textEmp.setText(recl.getEmpresa());
		textRecl.setText(recl.getReclamacao());
		
		boolean resposta = recl.isSituacao();
		
		if (!resposta){
			imgSituation.setImageResource(R.drawable.ic_respondido);
		} else {
			imgSituation.setImageResource(R.drawable.ic_pendente);
		}
		
		return lineView;
	}
}